package day6;

import java.util.Arrays;
import java.util.Scanner;

public class Main3 {
    /**
     * 加减
     * https://ac.nowcoder.com/acm/problem/224938
     */
    public static long[] arr; // 记录每个位置的值
    public static long[] sum; // 记录前i个数的和

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long k = in.nextLong();
        arr = new long[n + 1];
        sum = new long[n + 1];
        for(int i = 1;i <= n;i++) {
            arr[i] = in.nextLong();
        }

        // 贪心: 挨得最近的数，让他们变成相同的数
        // 排序
        Arrays.sort(arr,1,n + 1);

        // 前缀和，进行统计数据的值
        for(int i = 1;i <= n;i++) {
            sum[i] = sum[i - 1] + arr[i];
        }
        int ret = 0;
        // 利用滑动窗口，进行计算最长的区间
        int left = 1,right = 1;
        while(right <= n) {
            long cost = cal(left,right);
            // 出窗口
            while(cost > k) {
                left++;
                cost = cal(left,right);
            }
            // 更新，并且入窗口
            ret = Math.max(ret,right - left + 1);
            right++;
        }

        System.out.println(ret);
    }

    public static long cal(int left,int right) {
        int mid = (left + right) / 2;
        return (mid - left) * arr[mid] - (sum[mid - 1] - sum[left - 1]) +
                (sum[right] - sum[mid]) -(right - mid) * arr[mid];
    }

}
